// 创建一个单例 Singleton
// 立即执行函数是创建闭包的手段之一
let CreateSingleton = (function() {
    console.log('创建单例');
    // 多了一层作用域，作用域链
    let instanse;//实例
    return function(name) {// construtor
        if(instanse) {
            return instanse;
        }
       this.name = name;
       return instanse = this;
      //instanse = this;

    }
})()
CreateSingleton.prototype.getName = function() {
   // console.log(this.name);
    return this.name;
}
let singleton=new CreateSingleton('GCH');
let d = new CreateSingleton('LWB');
console.log(singleton == d);
console.log(singleton);
console.log(singleton.getName());
console.log(d.getName())